package JVM.chapter02;

/**
 * 在 initialization 初始化过程中：
 *      jvm保证同一个类的 <init></init>只会被执行一次
 */
public class ClinitThreadTest {
    public static void main(String[] args) {
        Runnable runnable = () -> {
            System.out.println(Thread.currentThread().getName() + "开始执行");
            ThreadTestClass test  = new ThreadTestClass();
            System.out.println(Thread.currentThread().getName() + "结束执行");
        };

        Thread t1 = new Thread(runnable, "线程1");
        Thread t2 = new Thread(runnable, "线程2");

        t1.start();
        t2.start();
    }
}

class ThreadTestClass{
    static {
        if (true){
            System.out.println(Thread.currentThread().getName() + " 初始化当前类");
            while(true){

            }
        }

    }
}


